package project.dao.impl;

import java.sql.*;

/**
 * DAO父类
 */
public abstract class BaseDAO {
    /**
     * 连接
     */
    protected Connection con;
    /**
     * SQL执行对象
     */
    protected PreparedStatement ps;
    /**
     * 结果集
     */
    protected ResultSet rs;

    public void setConnection() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            con = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/lesson1?userSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT",
                    "root","555430");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public void closeConnection(){
        try {
            if (rs!=null){
                rs.close();
            }
            if (ps!=null){
                ps.close();
            }
            if (con!=null){
                con.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
